/*
 * @Author: TC 
 * @Date: 2025-05-25 20:44:46 
 * @Last Modified by:   TC 
 * @Last Modified time: 2025-05-25 20:44:46 
 */

import { sp } from "cc";
import { EDITOR } from "cc/env";

/**
 * 定制引擎Spine
 */
export namespace nsCCSpine {
    if (EDITOR) {
        sp.Skeleton.prototype["updateAnimation"] = function (dt: number): void {
            this.markForUpdateRenderData();

            // if (this.paused) return;
            dt *= this._timeScale * 1;
            if (this.isAnimationCached()) {
                if (this._isAniComplete) {
                    if (this._animationQueue.length === 0 && !this._headAniInfo) {
                        const frameCache = this._animCache;
                        if (frameCache && frameCache.isInvalid()) {
                            frameCache.updateToFrame(0);
                            const frames = frameCache.frames;
                            this._curFrame = frames[frames.length - 1];
                        }
                        return;
                    }
                    if (!this._headAniInfo) {
                        this._headAniInfo = this._animationQueue.shift()!;
                    }
                    this._accTime += dt;
                    if (this._accTime > this._headAniInfo?.delay) {
                        const aniInfo = this._headAniInfo;
                        this._headAniInfo = null;
                        this.setAnimation(0, aniInfo?.animationName, aniInfo?.loop);
                    }
                    return;
                }
                this._updateCache(dt);
            } else {
                this._instance!.updateAnimation(dt);
            }
        };
    }
}
